package extrace.loader;

import android.app.Activity;

import com.google.gson.reflect.TypeToken;
import com.lljjcoder.bean.CustomCityData;

import java.util.List;

import extrace.misc.model.RegionAndTransNodeData;
import extrace.net.HttpAsyncTask;
import extrace.net.HttpResponseParam;
import extrace.net.IDataAdapter;
import extrace.net.JsonUtils;
import extrace.ui.main.ExTraceApplication;

public class RegionDataLoader extends HttpAsyncTask {
    String url;
    IDataAdapter<List<CustomCityData>> adapter;

    public RegionDataLoader(IDataAdapter<List<CustomCityData>> adpt, Activity context) {
        super(context);
        adapter = adpt;
        url = ((ExTraceApplication)context.getApplication()).getMiscServiceUrl();
    }

    @Override
    public void onDataReceive(HttpResponseParam param) {
        List<CustomCityData> testList = JsonUtils.fromJson(param.getResponseString(), new TypeToken<List<CustomCityData>>(){});
        adapter.setData(testList);
        adapter.notifyDataSetChanged();
    }

    @Override
    public void onStatusNotify(HttpResponseParam.RETURN_STATUS status, String str_response) {

    }
    public void getAllRegionAndTransNodeList()
    {
        String _url = url + "getAllRegionAndTransNodeList?_type=json";
        try {
            execute(_url, "GET");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void getAllProvinceAndTransNodeList(){
        System.out.println("url = "+url);
        String _url = url + "getAllProvinceAndTransNodeList?_type=json";
        try{
            execute(_url,"GET");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
